package com.example.hf_v1.service.Impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hf_v1.entity.Recharge;
import com.example.hf_v1.entity.User;
import com.example.hf_v1.entity.Vo.UserVo;
import com.example.hf_v1.mapper.UserMapper;
import com.example.hf_v1.service.UserService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public List<UserVo> selectAllUser() {
        MPJLambdaWrapper<User> lambdaWrapper = new MPJLambdaWrapper(User.class);
        lambdaWrapper.selectAs(User::getId,UserVo::getId)
                     .selectAs(User::getUsername,UserVo::getUsername)
                     .selectAs(User::getPassword,UserVo::getPassword)
                     .selectAs(User::getRole,UserVo::getRole)
                     .selectAs(User::getEmail,UserVo::getEmail)
                     .selectAs(User::getAvatar,UserVo::getAvatar)
                     .selectAs(User::getCreatedAt,UserVo::getCreatedAt)
                     .selectAs(User::getUpdatedAt,UserVo::getUpdatedAt)
                     .selectAs(User::getTelephone,UserVo::getTelephone)
                     .selectAs(User::getAge,UserVo::getAge)
                     .selectAs(User::getSex,UserVo::getSex)
                     .selectAs(User::getVip,UserVo::getVip)
                     .leftJoin(Recharge.class, Recharge::getRechargeUserId,User::getId)
                     .selectAs("max(recharge_over_time)",UserVo::getRechargeOverTime)
                     .selectAs(User::getAccountBalance,UserVo::getAccountBalance)
                     .groupBy("id")
                     .orderByAsc(User::getId)
                     .list();

           return userMapper.selectJoinList(UserVo.class, lambdaWrapper);
    }
}
